<?php

class m120529_121622_user_init extends EDbMigration {

	public function safeUp() {
		$columns = array(
			'id'=>'pk',
			'username'=>'varchar(20) NOT NULL',
			'password'=>'varchar(128) NOT NULL',
			'email'=>'varchar(128) NOT NULL',
			'activkey'=>"varchar(128) NOT NULL DEFAULT ''",
			'createtime'=>"integer NOT NULL DEFAULT 0",
			'lastvisit'=>"integer NOT NULL DEFAULT 0",
			'superuser'=>"integer NOT NULL DEFAULT 0",
			'status'=>"boolean NOT NULL DEFAULT 0",
		);
		$this->createTable('users', $columns);

		$columns = array(
			'id'=>1,
			'username'=>'admin',
			'password'=>'21232f297a57a5a743894a0e4a801fc3',
			'email'=>'andy.julot@gmail.com',
			'activkey'=>"21232f297a57a5a743894a0e4a801fc3 ''",
			'createtime'=>time(),
			'lastvisit'=>0,
			'superuser'=>1,
			'status'=>1,
		);
		$this->insert('users', $columns);

		$columns = array(
			'user_id'=>'pk',
			'lastname'=>"varchar(50) NOT NULL",
			'firstname'=>"varchar(50) NOT NULL",
			'birthday'=>'date',
		);
		$this->createTable('profiles', $columns);

		$columns = array(
			'user_id'=>1,
			'lastname'=>'Admin',
			'firstname'=>'Administrator',
			'birthday'=>'1977-07-23',
		);
		$this->insert('profiles', $columns);

		$columns = array(
			'id'=>'pk',
			'varname'=>"varchar(50) NOT NULL",
			'title'=>'string',
			'field_type'=>"varchar(50)",
			'field_size'=>"int(3) DEFAULT 0",
			'field_size_min'=>"integer DEFAULT 0",
			'required'=>"boolean DEFAULT 0",
			'match'=>'string',
			'range'=>'string',
			'error_message'=>'string',
			'other_validator'=>'text',
			'default'=>'string',
			'widget'=>'string',
			'widgetparams'=>'text',
			'position'=>"integer DEFAULT 0",
			'visible'=>"boolean DEFAULT 0",
		);
		$this->createTable('profiles_fields', $columns);

		$columns = array(
			'id'=>1,
			'varname'=>'lastname',
			'title'=>'Last Name',
			'field_type'=>"VARCHAR",
			'field_size'=>50,
			'field_size_min'=>3,
			'required'=>1,
			'error_message'=>'Incorrect Last Name (length between 3 and 50 characters).',
			'position'=>1,
			'visible'=>3,
		);
		$this->insert('profiles_fields', $columns);

		$columns = array(
			'id'=>2,
			'varname'=>'firstname',
			'title'=>'First Name',
			'field_type'=>"VARCHAR",
			'field_size'=>50,
			'field_size_min'=>3,
			'required'=>1,
			'error_message'=>'Incorrect First Name (length between 3 and 50 characters).',
			'position'=>0,
			'visible'=>3,
		);
		$this->insert('profiles_fields', $columns);

		$columns = array(
			'id'=>3,
			'varname'=>'birthday',
			'title'=>'Birthday',
			'field_type'=>"DATE",
			'field_size'=>0,
			'field_size_min'=>0,
			'required'=>2,
			'widget'=>'UWjuidate',
			'widgetparams'=>'{"ui-theme":"redmond"}',
			'position'=>3,
			'visible'=>2,
		);
		$this->insert('profiles_fields', $columns);
	}

	public function safeDown() {
		$this->dropTable('profiles_fields');
		$this->dropTable('profiles');
		$this->dropTable('users');
	}

}